package cn.edu.sdjzu.xg.eagle.Service;

import cn.edu.sdjzu.xg.eagle.dao.UserDao;
import cn.edu.sdjzu.xg.eagle.dao.UserDaoInterface;
import cn.edu.sdjzu.xg.eagle.entity.User;
import cn.edu.sdjzu.xg.eagle.factory.DaoFactory;
import cn.edu.sdjzu.xg.eagle.util.JdbcHelper;
import java.sql.Connection;
import java.sql.SQLException;



public class UserService implements UserServiceInterface{
    private static UserService userService = new UserService();
    public static UserService getInstance(){
        return userService;
    }
    private UserDaoInterface userDao = DaoFactory.getDao(UserDaoInterface.class,"UserDao");
    @Override
    public boolean add(User user, Connection connection) throws SQLException {
        return UserDao.getInstance().add(user, connection);
    }

    @Override
    public boolean delete(String usename, Connection connection) throws SQLException {
        return UserDao.getInstance().delete(usename, connection);
    }
    @Override
    public void login(User userToLogin) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        userDao.login(userToLogin, connection);
        JdbcHelper.close(connection);
    }

}
